﻿Imports SlimDX
Imports SlimDX.Direct3D9
Imports SlimDX.Direct3D11
Namespace Engine

    Public Class Lights

        Private Structure Vertex
            Public Position As Vector3
            Public Normal As Vector3

            Public Function SizeBytes() As Integer
                Return System.Runtime.InteropServices.Marshal.SizeOf(Me)
            End Function

            Public Function Format() As VertexFormat
                Return VertexFormat.Position Or VertexFormat.Normal
            End Function

        End Structure


        Public Vertices As VertexBuffer   '  Vertex buffer object used to hold vertices.
        Public time As Integer              ' Used for rotation caculations.
        Public angle As Double

        Public Sub Init(ByRef mDevice As SlimDX.Direct3D9.Device)

            ' Set up a material. The material here just has the diffuse and ambient
            ' colors set to white. Note that only one material can be used at a time.

            Dim Lmaterial As Material = New Material
            Lmaterial.Diffuse = New Color4(System.Drawing.Color.White)
            Lmaterial.Ambient = New Color4(System.Drawing.Color.White)
            mDevice.Material = Lmaterial

            ' Set up a white, directional light.
            ' Note that many Lights may be active at a time (but each one slows down
            ' the rendering of our scene). However, here we are just using one. Also,
            ' we need to set the D3DRS_LIGHTING renderstate to enable lighting
            Dim Thelight As Light = New Light

            Thelight.Type = LightType.Directional
            Thelight.Diffuse = New Color4(System.Drawing.Color.White)
            Thelight.Attenuation0 = 0.2F
            Thelight.Range = 1000.0F
            Thelight.Direction = New Vector3(0.0F, 0.0F, -1.0F)
            Thelight.Direction.Normalize()

            ' Set the light and enable lighting.
            mDevice.SetLight(0, Thelight)

            'mDevice.LightEnable(0, True)
            mDevice.SetRenderState(RenderState.Lighting, True)

            ' Set an ambient light.
            mDevice.SetRenderState(RenderState.Ambient, System.Drawing.Color.White.ToArgb())

        End Sub

    End Class
End Namespace
